/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.datebase;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author selkhateeb
 */
public class From {

    protected static String FROM = "FROM";
    private List<String> identifiers;
    private Where whereClause;
    private OrderBy orderByClause;
    private Select selectClause;

    // <editor-fold defaultstate="collapsed" desc="Getters">
    protected List<String> getIdentifiers() {
        return identifiers;
    }

    protected OrderBy getOrderByClause() {
        return orderByClause;
    }

    protected Where getWhereClause() {
        return whereClause;
    }
    // </editor-fold>

    public From(Class<?>... entities) {
        this.identifiers = new ArrayList<String>();
        for (Class<?> entity : entities) {
            this.identifiers.add(entity.getSimpleName());
        }
    }

    @Override
    public String toString() {
        return this.selectClause.toString();
    }

    protected String getClause() {
        String fromClause = FROM;
        for (String identifier : identifiers) {
            fromClause += " " + identifier;
        }
        return fromClause;
    }

    public Where Where() {
        return null;
    }

    public OrderBy OrderBy() {
        return null;
    }

    protected void setSelect(Select selectClause) {
        this.selectClause = selectClause;
        if (this.selectClause.getColumns().isEmpty()) {
            this.selectClause.getColumns().add(this.identifiers.get(0));
        }
    }
}
